#include "NTest.h"
#include <iostream>

NUNIT(TestUnit3, 3)
{
	// test performance
	NCOUNTER counter;
	counter.begin();

	for (int i = 0; i < 1000; ++i)
	{
		// do something...
	}

	counter.end();

	NPAUSE("%d", counter.difference());
}

NUNIT(TestUnit5, 0)
{

}

NUNIT(TestUnit4, 0)
{

}

NUNIT(TestUnit6, 2)
{

}

NUNIT(CrashTest, 0)
{
	NLOG("now run crash tests!");
	NLOG("crash test verify an operation will cause the system crashed!");

	// test access violation
	int * ptr = NULL;
	NCRASH(*ptr = 3);

	// test zero division
	int a = 0;
	int b;
	NCRASH(b = 1 / a);
}

NCASE(TestCaseSample)
{
	NTEST(TestFuncsSample)
	{
		NLOG(__FUNCTIONW__);
	}

	NTEST(TestFuncsSample2)
	{
		NLOG(__FUNCTION__);

		NPAUSE("Pause the test unit");
	}
};

NADD(TestCaseSample)


NCASE(IdCaseSample)
{
	void setup() 
	{
		Value = 3;

		Buffer = new char[1024];
		sprintf(Buffer, "Hello Ntest!!!");
	}

	void close()
	{
		delete[] Buffer;
		Buffer = NULL;
	}

	static void StaticUtil()
	{
		NLOG(__FUNCTION__);
	}

	void memberUtil()
	{
		NLOG(__FUNCTION__);
	}

	NTEST(TestFuncsSample)
	{
		NLOG(Buffer);

		NLOG("%d", Value);

		StaticUtil();

		memberUtil();
	}

	int Value;

	char * Buffer;
};

NREG(IdCaseSample, 1);

NCASE(IdCaseSample2)
{
	NTEST(TestFuncsSample)
	{

	}

	bool pause() { return true; }
};

NREG(IdCaseSample2, 9);